package mrusanov.ui.player

import javax.swing._
import net.miginfocom.swing.MigLayout
import mrusanov.player.Player
import mrusanov.view.Stand
import mrusanov.util.{SwingUtil, ImagePanel}
import mrusanov.localization.Localization
import java.util.Date

class PlayerSmallPanel(player:Player, now:Date) extends JPanel {

  setLayout(new MigLayout("fill", "[150px][150px]"))

  private def addList(msgKeyCaption:String, contents:Iterable[String]) {
    add(new JLabel(Localization(msgKeyCaption)), "span 2, align center, wrap")
    val list = new JList()
    val model = new DefaultListModel()
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
    contents foreach( model.addElement(_))
    list.setModel(model)
    add(list, "span 2, width 200px, height 80px, wrap, align center")
  }

  // TODO use team color
  add(new PlayerImage(player), "span 2, align center, wrap")

  SwingUtil.addLabel(this, "roster.table.name", player.name)
  SwingUtil.addLabel(this, "roster.table.playerType", player.playerType.name)
  SwingUtil.addLabel(this, "roster.table.level", player.level)
  SwingUtil.addLabel(this, "roster.table.age", player.age(now))
  SwingUtil.addLabel(this, "roster.table.physical", player.physicalShape)
  SwingUtil.addLabel(this, "playerPanel.hp", player.hp)
  SwingUtil.addLabel(this, "playerPanel.damage", player.damage)
  SwingUtil.addLabel(this, "playerPanel.damageType", Localization(player.playerType.damageType.messageKey))

  SwingUtil.addSingleLabel(this, "playerPanel.defences")
  player.playerType.defence.foreach (kv => {
    SwingUtil.addLabel(this, kv._1.messageKey, kv._2.toString + "%")
  })

  SwingUtil.addSingleLabel(this, "playerPanel.resistances")
  player.playerType.resistances.resistances.foreach(kv => {
    SwingUtil.addLabel(this, kv._1.messageKey, kv._2)
  })

  addList("playerPanel.friends", player.psychology.friends.map(_.name))
  addList("playerPanel.enemies", player.psychology.enemies.map(_.name))


}
